services:
  # Block for determining the parameters of server software for processing data from a smart set-top box
  smart-box:
    # Following instructions for building the image and port forwarding are given as an example. 
    # You need to define your own.
    build:
      context: ./smart-box
      args:
        alt_version: p10
        user_name: user
    ports:
      - '3333:49150'
      - '3334:49151'
    # Necessary instruction is to connect the volume to the logs.
    # In this case, the server software writes logs to the /var/log/smart-box. In file "log"
    volumes:
      - logs:/var/log/smart-box
    # For the server software, it is recommended to allocate a separate network for security.
    # In this case - box-net
    networks:
      box-net: {}
 
  promtail:
    image: grafana/promtail:latest
    # It is important to connect to metrics collection agent the volume that was connected for server software logs.
    # In the promtoil configuration file, specify the logы to collect from the previously connected volume.
    volumes:
      - logs:/var/log/smart-box
      - ./promtail/config.yml://etc/promtail/config.yml
    command: -config.file=/etc/promtail/config.yml
    networks:
      met-net:
        ipv4_address: 10.111.111.2
 
  loki:
    image: grafana/loki:latest
    ports:
      - "3100:3100"
    command: -config.file=/etc/loki/local-config.yaml
    networks:
      met-net:
        ipv4_address: 10.111.111.3

  grafana:
    environment:
      - GF_PATHS_PROVISIONING=/etc/grafana/provisioning
    entrypoint:
      - sh
      - -euc
      - |
        mkdir -p /etc/grafana/provisioning/datasources
        cat <<EOF > /etc/grafana/provisioning/datasources/ds.yaml
        apiVersion: 1
        datasources:
        - name: Loki
          type: loki
          access: proxy
          orgId: 1
          url: http://10.111.111.3:3100
          basicAuth: false
          isDefault: true
          version: 1
          editable: false
        EOF
        /run.sh
    image: grafana/grafana:latest
    # The port for web access to Grafana is specified for example.
    # You need to define your own.
    ports:
      - "3334:3000"
    networks:
      met-net:
        ipv4_address: 10.111.111.4

volumes:
  logs:
    driver: local

networks:
  box-net:
    driver: bridge
  met-net:
    driver: bridge
    ipam:
      config:
        - subnet: 10.111.111.0/24
          gateway: 10.111.111.1
